
public class Main {
 private char[] mych = new char[]{'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'};
    private char[] mych_2 = new char[]{'q','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','w','m'};
    private char[] mych_3 = new char[]{'q','e','r','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','t','n','w','m'};

    private int getHashCode(String str){
        int length = str.length();
        int code = 0;
        for(int i = 0; i < str.length(); i++){
            code += (str.charAt(i)-'a');
        }
        return code;
    }
    private int getTranHashCode(String str){
        int length = str.length();
        int code = 0;
        for(int i = 0; i < str.length(); i++){
            code += mych[str.charAt(i)-'a'];
            code += mych_2[str.charAt(i)-'a']*26*27;
            code += mych_3[str.charAt(i)-'a']*26;
        }
        return code;
    }
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<Integer, Map<Integer, List<String>>> map = new LinkedHashMap<>();
        List<List<String>> result = new ArrayList<>();
        for(int i = 0; i < strs.length; i++){
            int code = getHashCode(strs[i]);
            int tranCode = getTranHashCode(strs[i]);
            //System.out.println(tranCode);
            Map<Integer, List<String>> listMap = map.get(code);
            if(listMap == null){
                listMap = new LinkedHashMap<>();
                map.put(code ,listMap);
            }
            List<String> list = listMap.get(tranCode);
            if(list == null){
                list = new ArrayList<>();
                listMap.put(tranCode, list);
            }
            list.add(strs[i]);
        }
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Map<Integer, List<String>> mapEntry = (Map<Integer, List<String>>)entry.getValue();
            Iterator mapIt = mapEntry.entrySet().iterator();
            while(mapIt.hasNext()){
                Map.Entry listEntry = (Map.Entry) mapIt.next();
                result.add((List<String>)listEntry.getValue());
            }
        }
        return result;
    }
}

